package com.geekgo.flowcontroller.common;

import com.geekgo.flowcontroller.annotation.RateLimit;
import com.geekgo.flowcontroller.core.RateLimitStrategy;
import org.apache.commons.lang3.StringUtils;

/**
 * @author geekgo
 * @version 2016/8/3 17:33
 */
public class RateLimitBean {

    private String key;
    private double rate;
    private RateLimitStrategy strategy;


    public RateLimitBean() {
    }

    public RateLimitBean(RateLimit limit, Class<?> clazz) {
        this(StringUtils.isEmpty(limit.key())?clazz.getName():limit.key(),limit.rate(),limit.strategy());
    }


    public RateLimitBean(String key, double rate, RateLimitStrategy strategy) {
        this.key = key;
        this.rate = rate;
        this.strategy = strategy;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }

    public RateLimitStrategy getStrategy() {
        return strategy;
    }

    public void setStrategy(RateLimitStrategy strategy) {
        this.strategy = strategy;
    }

    public RateLimitBean cloneOne(){
        RateLimitBean limitBean = new RateLimitBean();
        limitBean.setKey(getKey());
        limitBean.setRate(getRate());
        limitBean.setStrategy(getStrategy());
        return limitBean;
    }
}
